package com.qf.advice;

import com.qf.bean.AjaxMessage;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

@Component
@Aspect
@EnableAspectJAutoProxy
public class MyAdvice {

    @Pointcut("execution(* com.qf.controller.*.*(..))")
    private void cut1(){}

    @Around("cut1()")
    public Object aroundSelect(ProceedingJoinPoint point){
        try {
            Object result = point.proceed(point.getArgs());
            return result;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
//            System.out.println("查询有异常");
            return new AjaxMessage<>(1,"服务器数据异常，请稍后再试");
        }
    }

}
